var interval;
var dataTable;

$("#autoRefresh").change(function () {
    if (this.checked) {
        autoRefresh()
    } else {
        clearInterval(interval)
    }
});
var autoRefresh = function () {
    interval = setInterval(function () {
        dataTable.ajax.reload(function () {

        }, false)
    }, 1000)
};

var createDownTask = function () {
    layer.open({
        type: 2,
        area: ['500px', '360px'],
        content: "create-down-task"
    })
};
var createConvertTask = function () {
    layer.alert("功能未开发")
    // layer.open({
    //     type: 2,
    //     area: ['500px', '560px'],
    //     content: "create-convert-task"
    // })
};

var del = function (id) {
    $.ajax({
        type: 'delete',
        url: '/api' + location.pathname + '/' + id,
        success: function (result) {
            layer.alert(result.msg, function (index) {
                dataTable.ajax.reload();
                layer.close(index)
            })
        }
    });
};
var convert = function (id) {
    $.ajax({
        type: 'post',
        data: {
            sourceMediaId: id
        },
        url: '/api/convert-task',
        success: function (result) {
            layer.alert(result.msg, function (index) {
                dataTable.ajax.reload();
                layer.close(index)
            })
        }
    });
};
var download = function (id) {
    location.href = '/api' + location.pathname + '/' + id + '/' + 'download'
};
